package com.atguigu.spbt.test1214.controller;


import com.atguigu.spbt.test1214.bean.Customer;
import com.atguigu.spbt.test1214.service.CustomerPlusService;
import com.atguigu.spbt.test1214.service.CustomerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //标注该类是controller  请求入口类
public class TestController {

    @Autowired
    CustomerService customerService ;

    @Autowired
    CustomerPlusService customerPlusService;



    @RequestMapping("/hello")   //把请求路径与方法做映射
    public String getHelloWorld(@RequestParam("name") String name , @RequestBody Customer customer ){
        System.out.println("Customer:"+customer);
        customerService.saveCustomer(customer);
        return "hello ,"+name;
    }


    @RequestMapping("/customer/list")
    public List<Customer> getCustomerList(){
    //    return   customerService.getCustomerList();
        List<Customer> shList = customerPlusService.list(new QueryWrapper<Customer>().eq("address", "sh"));

        return shList;
    }

    @PostMapping("/customer")
    public String saveCustomer( @RequestBody Customer customer ){
        //    return   customerService.getCustomerList();

          customerPlusService.saveOrUpdate(customer);// 保存还是修改 ？ 看主键 看传递的对象是主键有值

// 要做bean上对主键字段进行标识
        return "success";
    }



}
